package com.kfm.bootdemo.service;

import cn.hutool.crypto.SecureUtil;
import com.kfm.bootdemo.dao.UserDao;
import com.kfm.bootdemo.model.KfmUser;

import java.sql.SQLException;

public class UserService {


    private UserDao dao = new UserDao();

    public KfmUser login(String username, String password) {
        if (username == null || password == null) {
            return null;
        }
        try {
            return dao.selectByUsernameAndPassword(username, SecureUtil.md5(password));
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }

    public int register(String username, String password, String email) {
        // 对密码进行加密
        String s = SecureUtil.md5(password);
        try {
            return dao.insertUser(username, s, email);
        } catch (SQLException e) {
            e.printStackTrace();
            return -1;
        }
    }
}
